package com.kaifamiao.month04.day15;

import java.util.Iterator;

public class Test {

    public static void main(String[] args) {
        ArrayList list = new ArrayList();
        Hero hero1 = new Hero("张三", 20);
        Hero hero2 = new Hero("李四", 20);
        Hero hero3 = new Hero("王五", 20);
        Hero hero4 = new Hero("孙六", 20);
        list.add(hero1);
        list.add(hero2);
        list.add(hero3);
        list.add(hero4);

        for (int i = 0; i < list.size(); i++) {
            System.out.println(list.get(i));
        }

        for (Object obj : list) {
            System.out.println(obj);
        }

        Iterator it = list.iterator();
        while (it.hasNext()) {
            Hero hero = (Hero)it.next();
            System.out.println(hero);
        }
    }

    public static class Hero {
        String name;
        int age;

        public Hero(String name, int age) {
            this.name = name;
            this.age = age;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public int getAge() {
            return age;
        }

        public void setAge(int age) {
            this.age = age;
        }

        @Override
        public String toString() {
            return "Hero{" +
                    "name='" + name + '\'' +
                    ", age=" + age +
                    '}';
        }
    }

}
